package sk.lukaskrupa.guess.the.color.listeners;

import sk.lukaskrupa.guess.the.color.logging.Logging;
import sk.lukaskrupa.guess.the.color.ui.ColorPicker;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

/**
 * Provide handlers for common button actions.
 * 
 * @author Lukas Krupa (lukas0krupa@gmail.com)
 * 
 */
public class CommonButtonListener implements OnClickListener {

	private static Logging logger = Logging.getLog(CommonButtonListener.class);

	private final ColorPicker colorPicker;

	/**
	 * Creating Listener and saving mainView, for callback.
	 * 
	 * @param colorPicker
	 *            to show
	 */
	public CommonButtonListener(ColorPicker colorPicker) {
		this.colorPicker = colorPicker;
	}

	/**
	 * When clicking on Button.
	 */
	public void onClick(View v) {
		if (v instanceof ImageButton) {
			logger.debug("onClick", "You clicked button ID=" + v.getId() + ".");
			colorPicker.showColorPicker((ImageButton) v);
		} else {
			logger.warn(
					"onClick",
					"Listener call on some other component that Button. ["
							+ v.getClass() + "]");
		}
	}

}
